﻿using Sunny.UI;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace OtherDevice
{
    public partial class Form_sino二色温 : Form_ControlBase
    {
        public Form_sino二色温()
        {
            InitializeComponent();
        }
        SpecialLightCtrlBase lightCtrlBase;
        public override void FlushToDlg(object devicebase)
        {
            try
            {
                if (devicebase == null)
                    return;
                this.lightCtrlBase = devicebase as SpecialLightCtrlBase;
                this.Dock = DockStyle.Fill;
                this.Show();
            }
            catch (Exception)
            {

            }
        }

        private void btn_打开_Click(object sender, EventArgs e)
        {
            try
            {
                int ch = comboBox1.SelectedIndex;
                if (ch == -1)
                {
                    MessageBox.Show("请选择通道");
                    return;
                }
                if (int.TryParse(txt_亮度值.Text, out int value))
                {
                    if (value > 4000 && comboBox1.SelectedText == "红外")
                    {
                        value = 4000;
                    }
                    else if (value > 255 && comboBox1.SelectedText == "白光")
                    {
                        value = 255;
                    }
                    else if (value < 0)
                    {
                        value = 0;
                    }
                    lightCtrlBase.Set(ch, value);
                }
                else
                {
                    if (comboBox1.SelectedText == "红外")
                    {
                        MessageBox.Show("请输入0-4000亮度值");
                    }
                    else
                    {
                        MessageBox.Show("请输入0-255亮度值");

                    }
                    return;
                }
            }
            catch (Exception ex)
            {
                UIMessageBox.ShowError($"关闭光源出错:{ex.Message}+{ex.StackTrace}");
            }
        }

        private void btn_关闭_Click(object sender, EventArgs e)
        {
            try
            {
                int ch = comboBox1.SelectedIndex;
                if (ch == -1)
                {
                    MessageBox.Show("请选择通道");
                    return;
                }

                lightCtrlBase.Set(ch, 0);
            }
            catch (Exception ex)
            {
                UIMessageBox.ShowError($"关闭光源出错:{ex.Message}+{ex.StackTrace}");
            }
        }

        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            if(comboBox1.SelectedIndex == 0)
            {
                lb_亮度值.Text = "亮度值：（0-255）";
            }
            else
            {
                lb_亮度值.Text = "亮度值：（0-4000）";
            }
        }

        private void Form_sino二色温_Initialize(object sender, EventArgs e)
        {
            comboBox1.SelectedIndex = 0;
        }
    }
}
